<?php echo $this->BlkListProducts(); ?>

<?php
	$ssFilter = $this->arrParam['ssFilter'];
	$langTmp = $ssFilter['lang'];
	if($langTmp == ''){
		$langTmp = 'vi';
	}else{
		$langTmp = $ssFilter['lang'];
	}
	
	$page = 1;
	
	$lang = $this->arrParam['lang'];
    if(empty($lang)){
    	$lang = 'vi';
    }else{
    	$lang = $this->arrParam['lang'];
    }
	
	$urlHome 		= array('module'=>'default','controller'=>'index','action'=>'index','lang'=>$langTmp);
   	$linkHome 		= $this->url($urlHome,'home');
?>

<?php
	$item = $this->Item;
	$name = $item['name'];
	$summary 	= $item['summary'];
	$summary 	= str_replace("\\"," ",$summary);
	$content 	= $item['content'];
	$content 	= str_replace("\\"," ",$content);
	$created 	= $item['created'];
	
	if(!empty($item['picture'])){
	    $linkImg	= FILES_URL . '/news/images450x450/' . $item['picture'];
	    $linkImg2	= FILES_URL . '/news/orignal/' . $item['picture'];
	    $picture 	= '<img src="'. $linkImg .'" alt="'.$name.'" />';
	    $image 		= '<img src="'. $linkImg .'" alt="'.$name.'" />';
    }else{
	    $linkImg	= FILES_URL . '/news/images100x100/no-image.jpg';
	    $picture 	= '<img src="'. $linkImg .'" alt="'.$name.'" />';
	    $image 		= '<img src="'. $linkImg .'" alt="'.$name.'" />';
    }
    $cat 		= $this->Cat;
    $category	= $cat['name'];
//    $urlOptions = array('module'=>'news','controller'=>'index',
//						'action'=>'category',
//                    	'tid'=> $this->arrParam['nid'],
//						'name'=>$cat['alias'],
//                    	'lang'=>$lang,
//                    	'page'=>$page);
//   	$linkDetail = $this->url($urlOptions,'news-category');
   	$id = $item['id'];
?>
<script type="text/javascript">
		function fancyBox(elem){
			elem = $(elem);
			if (!elem.data("fancybox")) {
				elem.data("fancybox", true);
				elem.fancybox({
					'titleShow' 	: false,
					'transitionIn'	: 'elastic',
					'transitionOut'	: 'elastic',
					'centerOnScroll': true
				}).trigger('click');
			}
			return false; 
		}
	</script>
	
<div class="content margin-top-20">
                <div class="group-new02 width-100">
                    <div class="group-new02-title">
                        <div class="sub-left color-main">
                            <a class="link-sub" href="#"><img src="<?php echo $this->imgUrl;?>/icons/icon-flower.png" alt=""  /></a>
                            <p>Tin Tức</p>
                        </div>
                    </div>
                    <div class="group-new02-box">
                        <div class="box-news">
                            <h3><?php echo $name;?></h3>
                            <p><?php echo $content;?></p>
		                            <?php
		                        		$info = new Zendvn_System_Info();
										$memberInfo = $info->getMemberInfo('id');
										if($memberInfo != ''){
											$tbltUser 	= new Zendvn_Models_Users();
											$user 		= $tbltUser->listItem($this->arrParam,array('user_id'=>$memberInfo,'task'=>'public'));
											$group_id 	= $user['group_id'];
										}
										$email		=	$this->formText('email',null,array("class"=>"text"));
										$full_name	=	$this->formText('full_name',null,array("class"=>"text"));
										$email		=	$this->formText('email',null,array("class"=>"text"));
										$title		= 	$this->formText('title',null,array("class"=>"text"));
										$hidden		= 	$this->formHidden('news_id',$id,array("class"=>"text"));
										$hidUser	= 	$this->formHidden('user_id',$group_id,array("class"=>"text"));
										$content	= 	$this->formTextarea('content',null,array('rows'=>10));
										
										$captcha 	= 	$this->captcha;
										$txtCaptcha = 	$this->formText('captcha','');
										$txtID 		= 	$this->formHidden('captchaID',$this->captcha_id);		
										$urlCaptch		 = $this->baseUrl('default/index/captcha-image');	
										$inputCaptcha	= $this->formText('captcha',null,array("class"=>"code text"));
										
										$submit		= $this->formSubmit('Submit','Gửi bình luận');
										
										
										$formFullname 	= '<div class="lev">
															<span class="sub">Họ tên</span>'
															. $full_name . '</div>';
															
										$formEmail 		= '<div class="lev">
															<span class="sub">Email</span>'
															. $email . '</div>';
															
										$formTitle 		= '<div class="lev">
															<span class="sub">Tiêu đề</span>'
															. $title . $hidden . $hidUser .'</div>';
															
										$formContent 	= '<div class="lev">
														<span class="sub">Nội dung</span>'
														. $content . '</div>';
														
										$formSubmit  	= '<div class="lev">'
														. $submit .
														'</div>';
														
										if($group_id > 0){
											$input = $formTitle . $formContent ;
										}else{
											$input = $formFullname . $formEmail . $formTitle . $formContent ;
										}
		                        	?>
		                            
		                            
		                            
		                                <div class="form-contact">
		                                	<div class="title-form"><p>Ý kiến</p></div>
		                                	<div id="content-load" class="note"></div>
		                                	<?php
			                        			$linkSubmit =  $this->baseUrl($this->currentController . '/comment');
			                        		?>
		                                	<form id="cnt-comment" name="contact" action="<?php echo $linkSubmit;?>" method="post">
		                                    	<?php echo $input; ?>
		                                    	<div class="lev">
								                  <span>Nhập mã: </span>
								                  	<?php echo $inputCaptcha;?>                            	
								                  	<?php if(!empty($this->messageError['captcha'])):echo '<span class="msg_error">'.$this->messageError['captcha'].'</span>';endif;?>
								            	</div>
								            	<div class="lev">
								             		<div>
														<div class="border-img"><?php echo $txtID . $captcha;?></div>
								             	  	</div>
								            	 </div>
		                        			
		                        			<?php echo $formSubmit?>
								            	
		                                    </form>
		                                </div>

                                <div class="link-news">
                                    <div class="link-title">
                                        <p>Các tin liên quan</p>
                                    </div>
                                        <ul>
                                        <?php 
                                        $listNews	= $this->listNews;
                                        foreach($listNews as $ls){
                                        	$lsName		= $ls['name'];
                                        	$lsAlias	= $ls['alias'];
                                        	$lsId	= $ls['id'];
                                        	$urlOptions = array('module'=>'news',
								                               	'controller'=>'index',
								                                'action'=>'detail',
								                                'nname'=>$lsAlias,
								                                'id'=>$lsId,
								                                'lang'=>$lang);
							                $linkProduct = $this->url($urlOptions,'news-detail');
                                        ?>
                                            <li><a href="<?php echo $linkProduct;?>"><?php echo $lsName;?></a></li>
                                        <?php }?>    
                                        </ul>
                                </div>
            	</div> <!----------End DS- Content ----------->
        	<div class="clear"></div>
    	</div>
   	</div>
<!--------------------Content (End) ------------------------->
</div>	
				

<script type="text/javascript">
	//Khai bao ten cua form
	var formID = '#cnt-comment';
	//Khai bao ten cua vung hien du lieu tra ve
	var formMessage = '#content-load';
	var options = {
				target: formMessage,
				dataType: "json", 
				success: processData,
				};
	$(document).ready(function(){
		$(formMessage).ajaxSend(function(){
				$(formMessage).removeClass().addClass('loading').html('<img src="<?php echo $this->imgUrl . '/ajax-loader.gif';?>" alt="loading" />').fadeIn();
		});
		$(formID).submit(function(){
				$(this).ajaxSubmit(options);
				return false;
		});
	});

	function processData(data){
		if(data.type == 0){
			var success = 'Du lieu data duoc luu vao database';
			$(formMessage).addClass('success').html(success).fadeIn();
			$(formID).resetForm();
			$('#comment').slideUp(500);
			//$(formMessage).hide(10000);
			$(formMessage).delay(1500).fadeOut('slow');
			
		}else{
			var error = '';
			var msgError = data.err;
			for(x in msgError){
				error = error + msgError[x] + '<br>';
			}
			$(formMessage).removeClass().addClass('errors').html(error).fadeIn();
		}		
	}
</script>			
<script type="text/javascript">
	$('.btn-comment') .click(function(){
		$('#comment').slideToggle();
	})	
</script>

<script>
	function getData(data){
		$('.border-img').html(data);
		return false;
	}
	
	function refreshCaptcha(){
		var captchaID = $("#captchaID").val();
		$.get('<?php echo $urlCaptch . '/captchaID/';?>'+captchaID,getData);
	}
	$(document).ready(function(){
		$('#refresh').click(function(e){
			e.preventDefault();
			refreshCaptcha();
		});
	});
</script>
